/**
 * Created by hzh on 17/1/12.
 * 文件管理
 */
module.exports = function ($http, $q, httpservice) {
    var caseBarDetailFileService = {};


    /**
     * 上传文件
     * @param fileData
     */
    caseBarDetailFileService.uploadPhoto = function (fileData) {
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.fileUpUrl,
            data: fileData,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 文件下载列表
     */
    caseBarDetailFileService.fileDown = function () {
        var params = {};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.fileDownUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 文件上传列表
     * @param caseId 案件ID
     */
    caseBarDetailFileService.fileUpload = function (params) {
        // var params = {"caseId":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.fileUploadUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 上传列表的文件下载
     */
    caseBarDetailFileService.downUpFile = function (filename) {
        var params = {"fileName":filename};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.downUpFileUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 删除上传文件
     */
    caseBarDetailFileService.delUpFile = function (aliasTitle, fileName, creatorId, caseId) {
        var params = {"aliasTitle": aliasTitle, "caseId": caseId, "fileName": fileName, "creatorId": creatorId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.delUpFileUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    return caseBarDetailFileService;
};
